import 'dart:convert';

import 'package:dio/dio.dart';
import 'package:flustars_flutter3/flustars_flutter3.dart';
import 'package:flutter/material.dart';
import 'package:ls_work/common/common.dart';
import 'package:ls_work/login/login_router.dart';
import 'package:ls_work/net/HttpUtil.dart';
import 'package:ls_work/net/net.dart';
import 'package:ls_work/net/post_request.dart';
import 'package:ls_work/res/styles.dart';
import 'package:ls_work/routers/fluro_navigator.dart';
import 'package:ls_work/widgets/base_dialog.dart';
import 'package:ls_work/login/page/user_manager.dart';

class ExitDialog extends StatefulWidget {
  ExitDialog({
    Key? key,
  }) : super(key: key);

  @override
  _ExitDialog createState() => _ExitDialog();
}

class _ExitDialog extends State<ExitDialog> {
  @override
  Widget build(BuildContext context) {
    return BaseDialog(
      title: "提示",
      child: const Padding(
        padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
        child: const Text("您确定要退出登录吗？", style: TextStyles.textDark16),
      ),
      onPressed: _bindGeTuiClientId,
    );
  }

  void _bindGeTuiClientId() {
    var map = {'cid': SpUtil.getString(Constant.clientId)};
    HttpUtil.instance
        .getDio()
        .post(HttpApi.geTuiClientIdUnBind, data: map,options: PostRequest.urlencodedHeader)
        .then((r) {

      if (r.statusCode == 200) {
        Map<String, dynamic> map = json.decode(r.toString());
        if (map["code"].toString() == "0") {}
      } else {}
    }).catchError((e) {
      print(e.toString());
    });

    UserManager.instance.logout();
    NavigatorUtils.push(context, LoginRouter.loginPage, clearStack: true);
  }
}
